<?php
// 应用公共文件

function show($data, $message = 'success', $code = 200) {
    return json([
        'message' => $message,
        'code' => $code,
        'data' => $data
    ]);
}

function message($message = 'success', $code = 200) {
    return json([
        'message' => $message,
        'code' => $code
    ]);
}

// page, size
function setParam($params, $key) {
    return isset($params[$key]) && $params[$key] >= 1 ? $params[$key] : 1;
}
// 组合查询参数
function setWhereOpt($params, $key, $opt = '=') {
    if (isset($params[$key])) {
        if ($opt === 'like') {
            return [$key, $opt, '%'.$params[$key].'%'];
        } else {
            return [$key, $opt, $params[$key]];
        }
    }
}